package com.sunjob.mroresource.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunjob.common.domain.resource.Accessory;
import com.sunjob.common.domain.resource.System;
import com.sunjob.common.domain.resource.Vehicletype;
import com.sunjob.common.mroAnno.ControllerLog;
import com.sunjob.common.mroAnno.LogModuleType;
import com.sunjob.common.result.Result;
import com.sunjob.mroresource.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.builders.PathSelectors;

import java.util.List;

/**
 * @author: TomHuang
 * @date: 2022/8/23 0:25
 */
@RestController
@Api(tags = "配件与工具公共服务接口")
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @GetMapping("/find/allVehicletype/{pageNum}")
    @ResponseBody
    @ApiOperation(value = "查询所有适用车型")
    public Result<PageInfo> getAllVehicletype(@ApiParam(value = "分页页数") @PathVariable(required = false) int pageNum){
        PageHelper.startPage(pageNum,10);
        List<String> vehicletypes=commonService.selectAllVehicletype();
        if(vehicletypes.size()==0){
            return Result.fail("未查询到适用车型！");
        }
        PageInfo pageInfo=new PageInfo(vehicletypes);
        return Result.ok(pageInfo,"查询所有适用车型成功！");
    }

    @GetMapping("/find/allVehicletypeCount")
    @ResponseBody
    @ApiOperation(value = "查询所有适用车型数量")
    public Integer getAllVehicletypeCount(){
        int count= commonService.selectAllVehicletypeCount();
        return count;
    }

    @PostMapping("/add/vehicletype/{vehicletype}")
    @ApiOperation(value = "添加适用车辆")
    public Result<Integer> addVehicletype(@ApiParam(value = "适用车辆实体") @RequestBody Vehicletype vehicletype){
        int rt=commonService.insertVehicletype(vehicletype);
        if(rt==0){
            return Result.fail("新增适用车辆数据失败！");
        }
        return Result.ok(rt,"新增适用车辆数据成功！");
    }

    @PostMapping("/edit/vehicletype/{vehicletype}")
    @ApiOperation(value = "修改适用车型相关信息")
    public Result<Integer> editVehicletype(@ApiParam(value = "适用车型实体") @RequestBody Vehicletype vehicletype){
        int rt=commonService.updateVehicletype(vehicletype);
        if(rt==0){
            return Result.fail("修改适用车型数据失败！");
        }
        return Result.ok(rt,"修改适用车型数据成功！");
    }

    @GetMapping("/remove/vehicletype/{vehicletypeId}")
    @ApiOperation(value = "删除适用车型相关信息")
    public Result<Integer> removeVehicletype(@ApiParam(value = "适用车型id",required = true) @PathVariable Long vehicletypeId){
        int rt=commonService.deleteVehicletype(vehicletypeId);
        if(rt==0){
            return Result.fail("删除适用车型数据失败！");
        }
        return Result.ok(rt,"删除适用车型数据成功！");
    }

    @GetMapping("/find/allSystem/{pageNum}")
    @ResponseBody
    @ApiOperation(value = "查询所有专业系统")
    public Result<PageInfo> getAllSystem(@ApiParam(value = "分页页数") @PathVariable(required = false) int pageNum){
        PageHelper.startPage(pageNum,10);
        List<String> systems=commonService.selectAllSystem();
        if(systems.size()==0){
            return Result.fail("未查询到专业系统！");
        }
        PageInfo pageInfo=new PageInfo(systems);
        return Result.ok(pageInfo,"查询所有专业系统成功！");
    }

    @GetMapping("/find/allSystemCount")
    @ResponseBody
    @ApiOperation(value = "查询所有专业系统数量")
    public Integer getAllSystemCount(){
        int count= commonService.selectAllSystemCount();
        return count;
    }

    @PostMapping("/add/system/{system}")
    @ApiOperation(value = "添加专业系统")
    public Result<Integer> addSystem(@ApiParam(value = "专业系统实体") @RequestBody System system){
        int rt=commonService.insertSystem(system);
        if(rt==0){
            return Result.fail("新增专业系统数据失败！");
        }
        return Result.ok(rt,"新增专业系统数据成功！");
    }

    @PostMapping("/edit/system/{system}")
    @ApiOperation(value = "修改专业系统相关信息")
    public Result<Integer> editSystem(@ApiParam(value = "专业系统实体") @RequestBody System system){
        int rt=commonService.updateSystem(system);
        if(rt==0){
            return Result.fail("修改专业系统数据失败！");
        }
        return Result.ok(rt,"修改专业系统数据成功！");
    }

    @GetMapping("/remove/system/{systemId}")
    @ApiOperation(value = "删除专业系统相关信息")
    public Result<Integer> removeSystem(@ApiParam(value = "专业系统Id",required = true) @PathVariable Long systemId){
        int rt= commonService.deleteSystem(systemId);
        if(rt==0){
            return Result.fail("删除专业系统数据失败！");
        }
        return Result.ok(rt,"删除专业系统数据成功！");
    }

    @GetMapping("/find/allInoroutCount")
    @ResponseBody
    @ApiOperation(value = "查询所有出入库数量")
    public Integer getAllInoroutCount(){
        int count= commonService.selectAllInoroutCount();
        return count;
    }

    @GetMapping("/find/allInoroutInCount")
    @ResponseBody
    @ApiOperation(value = "查询所有入库数量")
    public Integer getAllInoroutInCount(){
        int count= commonService.selectAllInoroutInCount();
        return count;
    }

    @GetMapping("/find/allInoroutOutCount")
    @ResponseBody
    @ApiOperation(value = "查询所有出库数量")
    public Integer getAllInoroutOutCount(){
        int inCount= commonService.selectAllInoroutInCount();
        int count=commonService.selectAllInoroutCount();
        return count-inCount;
    }






}
